package com.redis.service;

import com.redis.annotation.CacheField;
import com.redis.annotation.CacheLock;
import com.redis.delay.test.TestOrder;
import com.redis.lock.SpelKeyGenerator;
import com.redis.topic.TestEvent;
import org.springframework.stereotype.Service;

import java.util.Random;

/**
 * @Description
 * @Author lizhilong
 * @Date 2020/12/9 18:52
 */
@Service
public class TestService {


    @CacheLock(prefix = "test",lockTime = 10,waitTime = 6,fair = false,keyGenerator = SpelKeyGenerator.class,keys = {"TestEvent.eventName","TestOrder.orderId"})
    public String test(@CacheField TestEvent testEvent, @CacheField TestOrder testOrder){
        System.out.println(Thread.currentThread().getName()+"-->"+testEvent.getEventName());
        try {
            Thread.sleep(5000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return testEvent.getEventName();
    }
}
